<!--
 * @Author: shenya
 * @Date: 2023-11-01 10:23:56
 * @Description: 页面列表
-->
<template>
  <basic-container>
    <avue-crud
      ref="crud"
      v-model="form"
      :page.sync="page"
      :data="tableData"
      :table-loading="tableLoading"
      :option="tableOption"
      :upload-change="$uploadChange"
      @on-load="getList"
      @search-change="searchChange"
      @refresh-change="refreshChange"
      @search-reset="searchReset"
      @size-change="sizeChange"
      @current-change="currentChange"
    >
      <template v-slot:pageAddress="{ row }">
        <div v-if="row.pageAddress">
          <el-image
            :src="row.pageAddress"
            :preview-src-list="[row.pageAddress]"
            style="width: 50px; height: 50px"
          />
        </div>
        <div v-else>未上传</div>
      </template>
      <template slot="menuLeft">
        <el-button
          type="primary"
          size="small"
          icon="el-icon-plus"
          @click="insertPage"
        >
          新增
        </el-button>
      </template>
      <template
        slot="menu"
        slot-scope="scope"
      >
        <el-button
          type="text"
          size="small"
          @click="editPage(scope.row)"
        >
          编辑
        </el-button>
      </template>
    </avue-crud>
    <add-dialog
      :id="id"
      ref="add"
      v-model="addVisible"
      :action="action"
      @refresh="getList"
    ></add-dialog>
  </basic-container>
</template>
<script>
import { selectPageList } from '@/api/operation/advertising';
import crudMixins from '@/mixins/crud';
import { tableOption } from '@/const/crud/advertising/page';
import addDialog from './components/addDialog.vue';
export default {
  components: {
    addDialog,
  },
  mixins: [crudMixins],
  data() {
    return {
      form: {},
      id: '',
      action: '',
      tableData: [],
      addVisible: false,
      tableOption: tableOption(),
      tableLoading: false,
    };
  },
  methods: {
    getList(page, refresh) {
      if (refresh) {
        this.page.current = 1;
        this.page.currentPage = 1;
      }
      this.tableLoading = true;
      selectPageList(
        Object.assign(
          {
            current: this.page.currentPage,
            size: this.page.pageSize,
          },
          this.searchForm
        )
      )
        .then((response) => {
          this.tableData = response.data.data.records;
          this.page.total = response.data.data.total;
          this.tableLoading = false;
        })
        .catch(() => {
          this.tableLoading = false;
        });
    },
    //新增
    insertPage() {
      this.action = 'add';
      this.addVisible = true;
    },
    //编辑
    editPage(row) {
      this.id = row.id;
      this.action = 'edit';
      console.log('row', row);
      this.addVisible = true;
    },
  },
};
</script>
<style lang="scss" scoped></style>
